package it.poli.IA;

import it.poli.IA.TilesGame.TileAction;
import it.poli.IA.TilesGame.TileNode;
import it.poli.IA.TilesGame.TileState;
import it.poli.IA.exceptions.FailureException;
import it.poli.IA.exceptions.NullActionException;
import it.poli.IA.space.Action;
import it.poli.IA.space.Node;
import it.poli.IA.space.State;
import it.poli.IA.strategies.AstarSearchStrategy;
import it.poli.IA.strategies.GraphSearchStrategy;
import it.poli.IA.strategies.SearchStrategy;
import it.poli.IA.strategies.Strategies;
import it.poli.IA.strategies.TreeSearchStrategy;

import java.util.Collection;

import java.util.List;


public class DecisionModule {
	
	public DecisionModule()
	{
		
	}
	
	
	public Collection<? extends Action> SomeSearch(Node s0, List<? extends Action> action, List<? extends State> Goals, Strategies strategy) throws FailureException
	{

		SearchStrategy strat = chooseStrategy(strategy);
		
		return strat.SomeSearch(s0, action, Goals, strategy);
		
	}
	
	private SearchStrategy chooseStrategy(Strategies strategy)
	{
		switch( strategy)
		{
			case BF_GraphSearch:
				return  new GraphSearchStrategy();
			case BF_TreeSearch:
				return new TreeSearchStrategy();
			case Astar_GraphSearch:
				return new AstarSearchStrategy();
				
		}
		return null;
	}
	
	

	/**
	 * Swap of element in position empty and element left, or up or down, or right
	 * @throws CloneNotSupportedException 
	 */
	public static State result(State currentState, Action a) throws CloneNotSupportedException 
	{
		
		return currentState.getResult(a);
	}

	public static boolean isAppliable(Action a, State currentState) throws NullActionException  {
		
			return currentState.isAppliable(a);
	}
	
	TileNode s0;
	List<TileAction> action;
	List<TileState> Goals;
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}
